﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

using HisGL.Log;
using HisGL.CA;
using HisGL.Crypto;
using HisGL.Json;

namespace NetCAService
{
  /// <summary>
  /// WS 的摘要说明
  /// </summary>
  [WebService(Namespace = "http://HisGL.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
  // [System.Web.Script.Services.ScriptService]
  public class WS : System.Web.Services.WebService
  {

    [WebMethod]
    public string DoAction(string inparm)
    {
      LogHelper.WriteLog(string.Format(@"功能:{0},入参inparm:{1}", "DoAction", inparm));

      ReqApiCA req = JsonHelper.JsonTo<ReqApiCA>(inparm);
      ResCA<string> res = CAManager.Instance.DoAction(req);
      string output = JsonHelper.ToJson(res);

      LogHelper.WriteLog(string.Format(@"DoAction出参:{0}", output));
      return output;
    }

    [WebMethod]
    public string DoAction2(string func, string injson)
    {
      LogHelper.WriteLog(string.Format(@"功能:{0},入参func:{1} injson:{2}", "DoAction2", func, injson));

      ReqApiCA req = new ReqApiCA();
      req.func = func;
      req.data = CryptoHelper.EncodeBase64("utf-8", injson);
      string sInput = JsonHelper.ToJson(req);

      string sOutput = DoAction(sInput);

      ResCA<string> res = JsonHelper.JsonTo<ResCA<string>>(sOutput);
      if (res.Data != "")
      {
        sOutput = CryptoHelper.DecodeBase64("utf-8", res.Data);
        LogHelper.WriteLog(string.Format(@"DoAction2 出参:{0}", sOutput));
      }
      return sOutput;
    }


  }
}
